﻿var type="1";//判断是哪个类型的请求，钉钉，微信

if(type=="1"){
	//alert("1")
}
else{
	define(["axios", "wx"], function (axios, wx) {
	    var latitude = "";
	    var longitude = "";

	    var url = window.location.href;
	    axios.get("/wechat/jssdk?url=" + url)
	        .then(function (response) {
	            wx.config({
	                beta: true,
	                debug: false,
	                appId: response.data.appId,
	                timestamp: response.data.timestamp,
	                nonceStr: response.data.nonceStr,
	                signature: response.data.signature,
	                jsApiList: ["getLocation", "scanQRCode", "startRecord", "stopRecord", "onVoiceRecordEnd", "translateVoice"]
	            });
	        });

	    wx.ready(function () {
	        wx.getLocation({
	            success: function (res) {
	                longitude = res.longitude.toString();
	                latitude = res.latitude.toString();
	            }
	        });
	    });

	    var location = function () {
	        return {
	            longitude: longitude,
	            latitude: latitude
	        }
	    }

	    var scan = function (callback) {
	        wx.scanQRCode({
	            desc: "scanQRCode desc",
	            needResult: 1,
	            scanType: ["qrCode", "barCode"],
	            success: function (res) {
	                callback(res.resultStr);
	            }
	        });
	    }

	    var startRecord = function (callback) {
	        wx.startRecord();
	        wx.onVoiceRecordEnd({
	            complete: function (res) {
	                var localId = res.localId;
	                translateVoice(localId, callback);
	            }
	        });
	    }

	    var stopRecord = function (callback) {
	        wx.stopRecord({
	            success: function (res) {
	                var localId = res.localId;
	                translateVoice(localId, callback);
	            }
	        });
	    }

	    var translateVoice = function (localId, callback) {
	        wx.translateVoice({
	            localId: localId,
	            isShowProgressTips: 1,
	            success: function (res) {
	                callback(res.translateResult);
	            }
	        });
	    }

	    return {
	        location: location,
	        scan: scan,
	        startRecord: startRecord,
	        stopRecord: stopRecord
	    }
	});
}
